package com.lagou.edu.handler;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 封装handler方法相关的信息
 */
public class Handler {

    /**
     * method.invoke(obj,)
     */
    private Object controller;
    /**
     * 方法
     */
    private Method method;
    /**
     * spring中url是支持正则的
     */
    private Pattern pattern;
    /**
     * 参数顺序,是为了进行参数绑定，key是形参名，value代表是第几个参数 <name,{2,type}>
     */
    private Map<String,Param> paramIndexMapping;
    /**
     * 权限控制
     * key : controllerSecurity methodSecurity
     */
    private Map<String,List<String>> security;

    public Handler(Object controller, Method method, Pattern pattern) {
        this.controller = controller;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>();
        this.security = new HashMap<>();
    }

    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Map<String, Param> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Param> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }

    public Map<String, List<String>> getSecurity() {
        return security;
    }

    public void setSecurity(Map<String, List<String>> security) {
        this.security = security;
    }
}
